//! Copyright 2012 Virtium Technology, Inc.
//! All rights reserved
//!
#ifndef __Counter_h__
#define __Counter_h__

#include "BasicTypes.h"
#include "SysTick.h"


class cCounter
{
private:
    #define LED_RED_ON      GPIO0_ON
    #define LED_RED_OFF     GPIO0_OFF
    #define LED_GREEN_ON    GPIO1_ON
    #define LED_GREEN_OFF   GPIO1_OFF
    #define SR_CLK_1        GPIO2_ON
    #define SR_CLK_0        GPIO2_OFF
    #define SR_DATA_1       GPIO3_ON
    #define SR_DATA_0       GPIO3_OFF
    #define SR_STB_1        GPIO4_ON
    #define SR_STB_0        GPIO4_OFF

    static const U8         DP_LED_SET = 0x20;
    static const U8         DP_LED_CLR = 0x00;

private:
    static cSysTick s_LedRedTick;
    static bool     s_LedRedIsOn;
    static cSysTick s_LedGreenTick;
    static bool     s_LedGreenIsOn;
    static cSysTick s_BeepTick;
    static bool     s_BeepIsOn;
    static U16      s_CardCount;

    static bool     s_NeedCheckTimePoint;
    static U16      s_pTimeZoneStart[];
    static U16      s_pTimeZoneEnd[];
    static U16      s_TimeZoneStatus;
    static U16      s_TimeZoneStatusOld;

    static U8       s_DpSetDv;
    static U8       s_DpSetCh;
    static U8       s_DpSetTr;
    static U8       s_DpSetNg;
private:
    static void ShiftLed(U8 iData);
public:
    static void SetLedOffTime(U8 iSecond);
    static void SetLedRed(bool on);
    static void SetLedGreen(bool on);
    static void SetBeep(bool sc);
    static bool SetCounter(U16 iVal);

    static inline void SetNeedCheckTimePoint()
    {
        s_NeedCheckTimePoint = true;
    }
    static void SetTimeZone(U8 iTpID, U16 iTimeZoneStart, U16 iTimeZoneEnd);
    static U16  GetTimeZone(U8 iTpID);

    static inline U16  GetCounter()
    {
        return (s_CardCount);
    }

    static void UpdateCounter();
    static bool IncCounter();

    static void InitReset();
    static void LoadConfig();
    static void UpdateTimeZone(U16 currMinute);
    static U16  GetTimeZoneStatus();
    static void RunOne();
};

#endif // __Counter_h__
